define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/index' + location.search,
                    add_url: 'order/add',
                    /*edit_url: 'order/edit',
                    del_url: 'order/del',*/
                    multi_url: 'order/multi',
                    import_url: 'order/import',
                    table: 'order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                escape: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'order_sn', title: __('Order_sn')},
                        {field: 'price', title: __('Price'), operate:false},
                        {field: 'discounted_price', title: __('Discounted_price'), operate:false},
                        {field: 'actual_price', title: __('Actual_price'), operate:false},
                        {field: 'goods', title: __("商品名称&nbsp;&nbsp;规格&nbsp;&nbsp;单价&nbsp;&nbsp;数量"), operate:false},
                        {field: 'username', title: __('用户名'), operate:false},
                        {field: 'mobile', title: __('Mobile'), operate:false},
                        {field: 'address', title: __('Address'), operate:false},
                        {field: 'paytype', title: __('Paytype'),searchList: {"1":__('Paytype 1'),"2":__('Paytype 2')}, formatter: Table.api.formatter.normal},
                        {field: 'paytime', title: __('Paytime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'deliverytime', title: __('Deliverytime'), operate:false},
                        {field: 'distribution_type', title: __('Distribution_type'), searchList: {"0":__('Distribution_type 0'),"1":__('Distribution_type 1')}, formatter: Table.api.formatter.normal},
                        /* {field: 'user.username', title: __('User.username'), operate: 'LIKE'},*/
                        {field: 'usercoupon.name', title: __('Usercoupon.name'), operate: 'LIKE'},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},
                        {field: 'note', title: __('Note'), operate:false},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},

                        /*{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}*/
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});